home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / util / moni / Scout-src.lha / source / objects / scout_print.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-02-13  |  3.9 KB  |  138 lines

  1. /**
  2.  * Scout - The Amiga System Monitor
  3.  *
  4.  *------------------------------------------------------------------
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  * You must not use this source code to gain profit of any kind!
  21.  *
  22.  *------------------------------------------------------------------
  23.  *
  24.  * @author Andreas Gelhausen
  25.  * @author Richard Körber <rkoerber@gmx.de>
  26.  */
  27.  
  28.  
  29.  
  30. #include "system_headers.h"
  31.  
  32. static char initialdrawer[TEXTLENGTH + 1];
  33. static char initialfile[FILENAMELENGTH + 1] = "prt:";
  34. static char printfilename[FILENAMELENGTH + 1] = "prt:";
  35.  
  36. int MyRequest (char *gadgets, char *fmt, ...)
  37. {
  38.    struct   EasyStruct myreqES;
  39.    struct   Window *myreq_window;
  40.    int      result;
  41.    ULONG    iflags = 0;
  42.    char     buf[256];
  43.  
  44.    va_list args;
  45.    va_start(args,fmt);
  46.    RawDoFmt(fmt, args, (void (*)())"\x16\xc0\x4e\x75", buf);
  47.  
  48.    get (WI_Main, MUIA_Window_Window, &myreq_window);
  49.  
  50.    myreqES.es_StructSize = sizeof(struct EasyStruct);
  51.    myreqES.es_Flags = 0;
  52.    myreqES.es_Title = "Scout Request";
  53.    myreqES.es_TextFormat = buf;
  54.    myreqES.es_GadgetFormat = gadgets;
  55.    result = EasyRequest (myreq_window, &myreqES, &iflags);
  56.  
  57.    va_end (args);
  58.    return (result);
  59. }
  60.  
  61. static BOOL FileRequest (void) {
  62.    struct   Window         *aslfr_window = NULL;
  63.    struct   FileRequester  *requester;
  64.    BOOL     result = FALSE;
  65.    char     endchar;
  66.  
  67.    get (WI_Main, MUIA_Window_Window, &aslfr_window);
  68.  
  69.    if (aslfr_window) {
  70.       if (requester = AllocAslRequestTags (ASL_FileRequest,
  71.                       ASLFR_Window, aslfr_window,
  72.                       ASLFR_PrivateIDCMP, TRUE,
  73.                       ASLFR_SleepWindow, TRUE,
  74.                       NULL)) {
  75.  
  76.          result = AslRequestTags (requester,
  77.                   ASLFR_TitleText, "Choose file or printer!",
  78.                   ASLFR_InitialDrawer, initialdrawer,
  79.                   ASLFR_InitialFile, initialfile,
  80.                   ASLFR_DoSaveMode, TRUE,
  81.                   NULL);
  82.  
  83.          strncpy (initialdrawer, requester->fr_Drawer, TEXTLENGTH);
  84.          strncpy (initialfile, requester->fr_File, FILENAMELENGTH);
  85.  
  86.          strcpy (printfilename, initialdrawer);
  87.          endchar = printfilename[strlen(printfilename) -1];
  88.  
  89.          if ((strlen(initialdrawer) != 0) && (endchar != '/') && (endchar != ':'))
  90.             strcat (printfilename, "/");
  91.          strcat (printfilename, initialfile);
  92.  
  93.          FreeAslRequest (requester);
  94.       }
  95.    }
  96.    return (result);
  97. }
  98.  
  99. BPTR PrintHandle;
  100. LONG PrintHandleMode = MODE_NEWFILE;
  101.  
  102. BPTR HandlePrintStart (char *filename) {
  103.    PrintHandle = (BPTR)NULL;
  104.  
  105.    if (AP_Scout) {
  106.       if ((! filename) && (! FileRequest()))
  107.          return ((BPTR)NULL);
  108.       ApplicationSleep();
  109.    } else if ((! filename) || (filename[0] == '\0')) {
  110.       return (Output());
  111.    }
  112.    if (filename) {
  113.       strncpy(printfilename, filename, FILENAMELENGTH);
  114.    }
  115.    if (! (PrintHandle = Open (printfilename, PrintHandleMode))) {
  116.       if (PrintHandleMode == MODE_OLDFILE) {
  117.          PrintHandle = Open (printfilename, MODE_NEWFILE);
  118.       }
  119.       if (! PrintHandle)
  120.          MyRequest ("Continue", "Couldn't open file \'%s\'!", printfilename);
  121.    }
  122.    if (PrintHandle) {
  123.       Seek (PrintHandle, 0, OFFSET_END);
  124.    }
  125.    return (PrintHandle);
  126. }
  127.  
  128. void HandlePrintStop (void) {
  129.    if (AP_Scout) {
  130.       AwakeApplication();
  131.    }
  132.    if (PrintHandle) {
  133.       Close (PrintHandle);
  134.    }
  135. }
  136.  
  137.  
  138.